

using SCADAEditor.Component;
using System;
using System.Collections.Generic;

namespace SCADAEditor.EventMan
{
    /// <summary>
    /// 事件管理器类，用于集中管理组态软件中的组件事件
    /// </summary>
    public class EventManager
    {
        // 使用字典存储事件名称和对应的处理委托
        private Dictionary<string, Action<ComponentBase>> _eventHandlers = new Dictionary<string, Action<ComponentBase>>();

        /// <summary>
        /// 注册事件处理器
        /// </summary>
        /// <param name="eventName">事件名称</param>
        /// <param name="handler">事件处理委托</param>
        public void RegisterEvent(string eventName, Action<ComponentBase> handler)
        {
            _eventHandlers[eventName] = handler;
        }

        /// <summary>
        /// 触发指定事件
        /// </summary>
        /// <param name="eventName">要触发的事件名称</param>
        /// <param name="component">触发事件的组件对象</param>
        public void TriggerEvent(string eventName, ComponentBase component)
        {
            if (_eventHandlers.ContainsKey(eventName))
            {
                _eventHandlers[eventName](component);
            }
        }
    }
}